/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Reinhard
 */
public class SearchModel {
  Connection connection;

  public SearchModel(Connection connection) {
    this.connection = connection;
  }

  public ResultSet searchUsername(String input) throws SQLException {
    String query = "SELECT * FROM user WHERE username LIKE '%" +input+"%'";
    System.out.println(query);
    Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = statement.executeQuery(query);
    return rs;
  }

  public ResultSet searchContent(String input) throws SQLException {
    String query = "SELECT ID FROM post WHERE title like '%" + input+"%'";
    System.out.println(query);
    Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = statement.executeQuery(query);
    return rs;
  }

  public ResultSet searchTag(String input) throws SQLException {
    String query = "SELECT post_id FROM post_tag INNER JOIN tag ON post_tag.tag_id = tag.ID WHERE tag.type like '%"+input+"%'";
    System.out.println(query);
    Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rs = statement.executeQuery(query);
    return rs;
  }
}
